package Week4.J0509;

import java.util.Scanner;

public class 装箱问题_xv {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int v = scanner.nextInt();
        int n = scanner.nextInt();

        int[] arr = new int[n + 1];

        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }

        int[][] dp = new int[n + 1][v + 1];
        for (int i = 1; i <= n; i++) {
            for (int j = 0; j <= v; j++) {
                dp[i][j] = dp[i - 1][j];
                if (j >= arr[i]) {
                    dp[i][j] = Math.max(dp[i][j],
                            dp[i - 1][j - arr[i]] + arr[i]);
                }
            }
        }
        System.out.println(v - dp[n][v]);
    }
}